//
//  LSChatRoomCell.m
//  LookScore
//
//  Created by wws on 2018/3/22.
//  Copyright © 2018年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSChatRoomCell.h"
#import "LSChatRoomModel.h"
@interface LSChatRoomCell()

@property (nonatomic, strong) UIImageView * iconImageView;
@property (nonatomic, strong) UILabel * niceNameLabel;
@property (nonatomic, strong) UILabel * contentLabel;


@end

@implementation LSChatRoomCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
+ (LSChatRoomCell *)chatRoomTableViewCellBytableView:(UITableView *)tableView{
    
    LSChatRoomCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell = [[LSChatRoomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addContentView];
    }
    return self;
    
}

- (UIImageView *)iconImageView{
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] init];
        _iconImageView.layer.cornerRadius = 9.5;
        _iconImageView.layer.masksToBounds = YES;
    }
    
    return _iconImageView;
}

- (UILabel *)niceNameLabel{
    
    if (!_niceNameLabel) {
        _niceNameLabel = [[UILabel alloc] init];
        _niceNameLabel.textColor = LSSubColor75b8fe;
        _niceNameLabel.font = LSFontSize12;
        
        
    }
    return _niceNameLabel;
}

- (UILabel *)contentLabel{
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc] init];
        _contentLabel.numberOfLines = 0;
        _contentLabel.textColor = LSSubColor5D5D5D;
        _contentLabel.font = LSFontSize12;
    }
    return _contentLabel;
}

- (void)addContentView{
    [self.contentView addSubview:self.niceNameLabel];
    [self.contentView addSubview:self.iconImageView];
    [self.contentView addSubview:self.contentLabel];
    
    self.iconImageView.sd_layout
    .leftSpaceToView(self.contentView, 5)
    .topSpaceToView(self.contentView, 5)
    .heightIs(19.5)
    
    .widthIs(19);
    self.niceNameLabel.sd_layout
    .leftSpaceToView(self.iconImageView, 5)
    .centerYEqualToView(self.iconImageView)
    .autoHeightRatio(0);
    [self.niceNameLabel setSingleLineAutoResizeWithMaxWidth:180];
    
    
    self.contentLabel.sd_layout
    .leftEqualToView(self.niceNameLabel)
    .topSpaceToView(self.niceNameLabel, 5)
    .rightSpaceToView(self.contentView, -5)
    .autoHeightRatio(0);
    
    
}

- (void)setModel:(LSChatRoomModel *)model{
    _model = model;
//    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?t%@",model.UserHeadUrl,[CommonClass readStampTimeString]]] placeholderImage:nil];
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.UserHeadUrl] placeholderImage:[UIImage imageNamed:@"MineDefaultHead"] options:SDWebImageRefreshCached];
    self.niceNameLabel.text = model.DisplayName;
    self.contentLabel.text = model.Msg;
    [self setupAutoHeightWithBottomView:self.contentLabel bottomMargin:5];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
